/**********************************************************************
  * @file:        xxx.c
  * @author:      guangjieMVP
  * @version:     v1.00.00
  * @date:        2020-xx-xx
  * @github:      https://github.com/guangjieMVP
  * @brief: 
************************************************************************/
/**********************************************************************
  * @file:        xxx.c
  * @author:      guangjieMVP
  * @version:     v1.00.00
  * @date:        2020-xx-xx
  * @github:      https://github.com/guangjieMVP
  * @brief: 
************************************************************************/
#include "stack_with_validator.h"

/**********************************************************************
  * @brief:         初始化带校验器的类    
  * @param[in]:     None
  * @retval[out]:   None
  * @note:              
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_with_validator_init(stack_with_validator_t *s, int *s_buffer, int size, stack_validator_t *validator)
{
    if(!s || !s_buffer || !validator)
        return -1;

    s->validator = validator;
    return stack_init(&s->super, s_buffer, size);
}

/**********************************************************************
  * @brief:         带校验器类的入栈函数    
  * @param[in]:     None
  * @retval[out]:   None
  * @note:              
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_with_validator_push(stack_with_validator_t *s, int val)
{
    if(!s)
        return -1;
    
    if(s->validator == NULL || stack_validate(s->validator, val) == 0)   //没有校验器或者校验通过
    {
        return stack_push(&s->super, val);
    }
    return -1;
}

/**********************************************************************
  * @brief:         带校验器类的出栈函数    
  * @param[in]:     None
  * @retval[out]:   None
  * @note:              
  * @author:        guangjieMVP
  * @github:        https://github.com/guangjieMVP
************************************************************************/
int stack_with_validator_pop(stack_with_validator_t *s, int *val)
{
    if(!s)
        return -1;

    return stack_pop(&s->super, val);
}

